﻿using System;
using System.Web;

namespace MikeKappel.Com.CS
{
    /// <summary>
    /// 301 redirect is the most efficient and Search Engine Friendly method for webpage redirection. 
    /// This should preserve your search engine rankings for that particular page.
    /// If you have to change file names or move pages around, this is the safest option. 
    /// The code "301" is interpreted as "moved permanently". 
    /// </summary>
    public static partial class Helper
    {
        /// <summary>
        /// 301 redirect
        /// "Moved Permanently"
        /// </summary>
        /// <param name="Url">Url the user will be redirected to.</param>
        public static void GoTo301(Uri Url)
        {
            GoTo301(Url.OriginalString);
        }
        /// <summary>
        /// 301 redirect 
        /// "Moved Permanently"
        /// </summary>
        /// <param name="Url">Url the user will be redirected to.</param>
        public static void GoTo301(String Url)
        {
            if (HttpContext.Current.Request.Url.OriginalString != Url)
            {
                HttpContext.Current.Response.Status = "301 Permanently Moved";
                HttpContext.Current.Response.StatusCode = 301;
                HttpContext.Current.Response.AddHeader("Location", Url);
                HttpContext.Current.Response.End();
            }
        }
    }
}